{include file='common/header'}
{include file='common/menu'}


<!-- Page Content -->
<div class="page-content">
    <!-- Page Breadcrumb -->
    <div class="page-breadcrumbs">
        <ul class="breadcrumb">
            <li>
                <a href="#">系统</a>
            </li>
            <li>
                <a href="{:url('auth_group/lis')}">用户组列表</a>
            </li>
            <li class="active">编辑用户组</li>
        </ul>
    </div>
    <!-- /Page Breadcrumb -->

    <!-- Page Body -->
    <div class="page-body">

        <div class="row">
            <div class="col-lg-12 col-sm-12 col-xs-12">
                <div class="widget">
                    <div class="widget-header bordered-bottom bordered-blue">
                        <span class="widget-caption">编辑用户组</span>
                    </div>
                    <div class="widget-body">
                        <div id="horizontal-form">
                            <form class="form-horizontal" role="form" action="" method="post">
                                <input type="hidden" name="id" value="{$auth_group.id}">
                                <div class="form-group">
                                    <label for="title" class="col-sm-2 control-label no-padding-right">用户组名称</label>
                                    <div class="col-sm-6">
                                        <input class="form-control" id="title" placeholder="" name="title" required="required" type="text" maxlength="100" value="{$auth_group.title}">
                                    </div>
                                    <p class="help-block col-sm-4 red">* 必填</p>
                                </div>

                                <div class="form-group">
                                    <label for="status" class="col-sm-2 control-label no-padding-right">是否启用</label>
                                    <div class="col-sm-6">
                                        <input {if condition="$auth_group.status eq 1"}checked{/if} class="checkbox-slider yesno" type="checkbox" id="status" name="status">
                                        <span class="text"></span>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label for="rules" class="col-sm-2 control-label no-padding-right">配置权限</label>
                                    <div class="col-sm-6">
                                        <table class="table table-hover">
                                            <thead class="bordered-darkorange">
                                            <tr>
                                                <th>权限</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            {volist name="auth_rules" id="auth_rule"}
                                            <tr>
                                                <td>
                                                    <label >
                                                        <?php echo str_repeat('&nbsp;', $auth_rule['level']*4)?>
                                                        <input name="rules[]" value="{$auth_rule.id}"
                                                               <?php $arr=explode(',', $auth_group['rules']); if(in_array($auth_rule['id'] ,$arr)){echo 'checked';}?>
                                                               dataid="id-{$auth_rule.dataid}" class="inverted checkbox-parent {if condition="$auth_rule['level'] neq 0"}checkbox-child{/if}"  name="title" type="checkbox" >
                                                        <span {if condition="$auth_rule['level'] eq 0"}style="font-weight: bolder;font-size:15px"{/if} class="text">{$auth_rule.title}</span>
                                                    </label>
                                                </td>
                                            </tr>
                                            {/volist}
                                            </tbody>
                                        </table>
                                    </div>
                                    <p class="help-block col-sm-4 red">* 必填 </p>
                                </div>

                                <div class="form-group">
                                    <div class="col-sm-offset-2 col-sm-10">
                                        <button type="submit" class="btn btn-default">保存信息</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
    <!-- /Page Body -->
</div>
<!-- /Page Content -->

{include file='common/footer'}

<script type="text/javascript">
    /* 权限配置 */
    $(function () {
        //动态选择框，上下级选中状态变化
        $('input.checkbox-parent').on('change', function () {
            var dataid = $(this).attr("dataid");
            $('input[dataid^=' + dataid + ']').prop('checked', $(this).is(':checked'));
        });
        $('input.checkbox-child').on('change', function () {
            var dataid = $(this).attr("dataid");
            dataid = dataid.substring(0, dataid.lastIndexOf("-"));
            var parent = $('input[dataid=' + dataid + ']');
            if ($(this).is(':checked')) {
                parent.prop('checked', true);
                //循环到顶级
                while (dataid.lastIndexOf("-") != 2) {
                    dataid = dataid.substring(0, dataid.lastIndexOf("-"));
                    parent = $('input[dataid=' + dataid + ']');
                    parent.prop('checked', true);
                }
            } else {
                //父级
                if ($('input[dataid^=' + dataid + '-]:checked').length == 0) {
                    parent.prop('checked', false);
                    //循环到顶级
                    while (dataid.lastIndexOf("-") != 2) {
                        dataid = dataid.substring(0, dataid.lastIndexOf("-"));
                        parent = $('input[dataid=' + dataid + ']');
                        if ($('input[dataid^=' + dataid + '-]:checked').length == 0) {
                            parent.prop('checked', false);
                        }
                    }
                }
            }
        });
    });
</script>